package com.hema.auction.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.hema.auction.R;
import com.hema.auction.base.BaseActivity;
import com.hema.auction.bean.SysUnits;
import com.hema.auction.utils.GlideUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bingoogolapple.bgabanner.BGABanner;

/**
 * 新手引导页
 * author by john
 */

public class GuideActivity extends BaseActivity {

    @BindView(R.id.guide)
    BGABanner guide;
    List<SysUnits> sysUnitses;
    @BindView(R.id.tv_enter)
    TextView tvEnter;
    @BindView(R.id.tv_skip)
    TextView tvSkip;

    private int[] locaGuide = new int[]{};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        }
        setContentView(R.layout.activity_guide);
        ButterKnife.bind(this);
        spManager.setShowGuide(true);
        init();

    }

    private void init() {
        guide.setEnterSkipViewIdAndDelegate(R.id.tv_enter, R.id.tv_skip, new BGABanner.GuideDelegate() {
            @Override
            public void onClickEnterOrSkip() {
                intentTo(MainActivity.class);
                finish();
            }
        });
//        sysUnitses = (List<SysUnits>) getIntent().getSerializableExtra(Constant.EXTRA_GUIDE);
        if(sysUnitses == null){
            guide.setData(R.drawable.ic_guide_01,R.drawable.ic_guide_02,R.drawable.ic_guide_03);
        }else {
            guide.setAdapter((banner1, view, model, position) -> {
                ImageView iv = (ImageView) view;
                iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
                GlideUtils.load(this, (String) model, iv);
            });
            List<String> imgs = new ArrayList<>();
            for (SysUnits sysUnits : sysUnitses) {
                imgs.add(sysUnits.getImg());
            }
            guide.setData(imgs, null);
        }

    }
}
